package com.swagger.wen.Exception;

import com.swagger.wen.bean.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class ExceptionHandlerAdvice {
    private static Logger LOGGER = LoggerFactory.getLogger(ExceptionHandlerAdvice.class);

    @ExceptionHandler(Exception.class)
    public JsonResult handleException(Exception e){
        LOGGER.error("这是ExceptionHandlerAdvice报出的错误");
        e.printStackTrace();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatus("-2");
        jsonResult.setMsg("未知的错误发生");
        jsonResult.setResult(e.getMessage());
        return jsonResult;
    }
}
